package packageTP2;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class lectureEcriture
{
  public lectureEcriture()
  {
  }

  public void lire() 
    throws IOException, Exception
  {
       InputStream inp;
    
    try
    {
      //Lecture Des clients
      inp = new FileInputStream("Clients.xlsx");
      XSSFWorkbook wb = (XSSFWorkbook) WorkbookFactory.create(inp);
      XSSFSheet sheet = wb.getSheetAt(0);
      int i =1;
      XSSFRow r = null;
      while(sheet.getRow(i) != null)
      {
        System.out.println("1");
        r = sheet.getRow(i);
        EnsembleClients.ajouterClient(new Client(String.valueOf((int)r.getCell(0).getNumericCellValue()),(String)r.getCell(1).getStringCellValue(),(int)r.getCell(2).getNumericCellValue()));
        
        //System.out.println(EnsembleClients.getClient(String.valueOf(r.getCell(0).getNumericCellValue())).getNoCarte());
        i++;
      }
      inp.close();
      //Lecture De l'inventaire
      inp = new FileInputStream("Produits.xlsx");
      wb = (XSSFWorkbook) WorkbookFactory.create(inp);
      sheet = wb.getSheetAt(0);
      i =1;
      while(sheet.getRow(i) != null)
      {
        System.out.println("2");
        r = sheet.getRow(i);
        Inventaire.ajouterProduit(new Produit((int)(r.getCell(0).getNumericCellValue()),r.getCell(1).getStringCellValue(),(int)r.getCell(2).getNumericCellValue(),r.getCell(3).getNumericCellValue(),(int)r.getCell(4).getNumericCellValue()));
        i++;
      }
      inp.close();
      
    }catch (FileNotFoundException e)
    {
    }

  

  }
}
